package com.xnyzc.lhy.order.controller.capi.user.wallet;


import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.exception.PangException;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.common.util.TokenUtil;
import com.xnyzc.lhy.order.service.user.wallet.IOaCWalletRecordService;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 * 用户钱包记录表 前端控制器
 * </p>
 *
 * @author zhuyubin
 * @since 2019-07-19
 */
@RestController
@RequestMapping("capi/walletRecord")
public class OaCWalletRecordController {

    @Autowired
    private IOaCWalletRecordService iOaCWalletRecordService;

    /**
     * 获取账单分页数据
     * @param type 列表类型
     * @param current 分页当前页(从1开始)
     * @return
     */
    @GetMapping(value = "selectWalletRecordPage")
    public Rv selectWalletRecordPage(
            @ApiParam(name = "type", value = "列表类型") @RequestParam(value = "type") Integer type,
            @ApiParam(name = "current", value = "分页当前页(从1开始)") @RequestParam(value = "current") Long current){
        Long userId = TokenUtil.getTokenUserId();
        if (CheckUtil.objIsEmpty(userId)){
            throw PangException.create(EErrorCode.tokenExpire);
        }
        String tag = TokenUtil.getTag();
        if (StringUtils.isEmpty(tag)){
            throw PangException.create(EErrorCode.missingAuthArgs);
        }
        return Rv.wrap(iOaCWalletRecordService.selectWalletRecordPage(userId, tag, type, current));
    }

    /**
     * 获取个人或部门列表
     * @param type 列表类型
     * @param current 分页当前页(从1开始)
     * @return
     */
    @GetMapping(value = "selectPersonageOrOfficialPage")
    public Rv selectPersonageOrOfficialPage(
            @ApiParam(name = "type", value = "列表类型") @RequestParam(value = "type") Integer type,
            @ApiParam(name = "current", value = "分页当前页(从1开始)") @RequestParam(value = "current") Long current){
        Long userId = TokenUtil.getTokenUserId();
        if (CheckUtil.objIsEmpty(userId)){
            throw PangException.create(EErrorCode.tokenExpire);
        }
        String tag = TokenUtil.getTag();
        if (StringUtils.isEmpty(tag)){
            throw PangException.create(EErrorCode.missingAuthArgs);
        }
        return Rv.wrap(iOaCWalletRecordService.selectPersonageOrOfficialPage(userId, tag, type, current));
    }

    /**
     * 账单详情
     * @param recordId 账单id
     * @return
     */
    @GetMapping(value = "getWalletRecord")
    public Rv getWalletRecord(@ApiParam(name = "recordId", value = "账单id") @RequestParam(value = "recordId") Long recordId){
        Long userId = TokenUtil.getTokenUserId();
        if (CheckUtil.objIsEmpty(userId)){
            throw PangException.create(EErrorCode.tokenExpire);
        }
        String tag = TokenUtil.getTag();
        if (StringUtils.isEmpty(tag)){
            throw PangException.create(EErrorCode.missingAuthArgs);
        }
        return Rv.wrap(iOaCWalletRecordService.getWalletRecord(userId, tag, recordId));
    }

    /**
     * 获取用车额度
     * @return
     */
    @GetMapping(value = "getVehicleSystem")
    public Rv getVehicleSystem(){
        Long userId = TokenUtil.getTokenUserId();
        if (CheckUtil.objIsEmpty(userId)){
            throw PangException.create(EErrorCode.tokenExpire);
        }
        String tag = TokenUtil.getTag();
        if (StringUtils.isEmpty(tag)){
            throw PangException.create(EErrorCode.missingAuthArgs);
        }
        return Rv.wrap(iOaCWalletRecordService.getVehicleSystem(userId, tag));
    }

    /**
     * 获取用户钱包记录
     * @param pageIndex
     * @param pageSize
     * @param type  0充值 1支出
     * @return
     */
    @GetMapping("getRechargeRecord")
    public Rv getRechargeRecord( Integer pageIndex,Integer pageSize,Integer type) {

        Long userId = TokenUtil.getTokenUserId();
        if (CheckUtil.objIsEmpty(userId)){
            throw PangException.create(EErrorCode.tokenExpire);
        }
        String tag = TokenUtil.getTag();
        if (StringUtils.isEmpty(tag)){
            throw PangException.create(EErrorCode.missingAuthArgs);
        }
        return iOaCWalletRecordService.getRechargeRecord(userId, tag,type, pageIndex,pageSize);
    }

//    /**
//     * 用户公务额度列表
//     * @param moneyType 额度类型（0 全部 1 收入 2 支出）
//     * @param current 当前页
//     * @return
//     */
//    @ApiOperation(value = "用户公务额度列表", notes = "用户公务额度列表")
//    @GetMapping(value = "selectOfficialMoneyPage")
//    public Rv<OaCWalletRecord> selectOfficialMoneyPage(
//            @ApiParam(name = "moneyType", value = "额度类型") @RequestParam(value = "moneyType") Integer moneyType,
//            @ApiParam(name = "current", value = "当前页") @RequestParam(value = "current") long current
//    ){
//        long userId = TokenUtil.getTokenUserId();
//        if (userId == 0){
//            throw PangException.create(EErrorCode.tokenExpire);
//        }
//        if (moneyType == null){
//            moneyType = 0;
//        }
//        return Rv.wrap(iOaCWalletRecordService.selectOfficialMoneyPage(userId, moneyType, current));
//    }
//
//    /**
//     * 用户公务额度列表详情
//     * @param recordId 列表id
//     * @return
//     */
//    @ApiOperation(value = "用户公务额度列表详情", notes = "用户公务额度列表详情")
//    @GetMapping(value = "getOfficialMoneyDetails")
//    public Rv<OaCWalletRecord> getOfficialMoneyDetails(
//            @ApiParam(name = "recordId", value = "列表id")@RequestParam(value = "recordId") Long recordId
//    ){
//        long userId = TokenUtil.getTokenUserId();
//        if (userId == 0){
//            throw PangException.create(EErrorCode.argCheckErr);
//        }
//        if (recordId == null){
//            throw PangException.create(EErrorCode.argCheckErr);
//        }
//        return Rv.wrap(iOaCWalletRecordService.getOfficialMoneyDetails(userId, recordId));
//    }
}
